package com.study.jyg.rxjava2study.activity;

import android.content.Intent;
import android.net.Uri;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;

import com.gamerole.orcameralib.CameraActivity;
import com.study.jyg.rxjava2study.R;
import com.study.jyg.rxjava2study.utils.glide.GlideUtils;

public class IDCardActivity extends AppCompatActivity {

    private final int REQUEST_CODE = 100;
    private ImageView ivPic;
    private String filePath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_i_d_card);
        ivPic = findViewById(R.id.ivPic);
        filePath = getFilesDir()+ "MyStudyFile";
        findViewById(R.id.btn1).setOnClickListener(v -> {
            Intent intent = new Intent(this, CameraActivity.class);
            intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH,filePath);
            intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_FRONT);
            startActivityForResult(intent, REQUEST_CODE);
        });
        findViewById(R.id.btn2).setOnClickListener(v -> {
            Intent intent = new Intent(this, CameraActivity.class);
            intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH,filePath);
            intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_BACK);
            startActivityForResult(intent, REQUEST_CODE);
        });
        findViewById(R.id.btn3).setOnClickListener(v -> {
            Intent intent = new Intent(this, CameraActivity.class);
            intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH,filePath);
            intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_GENERAL);
            startActivityForResult(intent, REQUEST_CODE);
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (RESULT_OK == resultCode){
            if (requestCode == REQUEST_CODE){
                Log.e("picPath", "hahha");
                GlideUtils.setBackgroud(ivPic, filePath);
            }
        }
    }
}